package com.vcc.web.core.component;


import com.vcc.service.service.ClearTranService;
import com.vcc.service.service.TransactionService;
import com.vcc.service.service.UserCardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TaskComponent {

    private static final Logger logger = LoggerFactory.getLogger(TaskComponent.class);

//    @Autowired
//    private PingPongComponent pingPongComponent;
    @Autowired
    private ClearTranService clearTranService;
    @Autowired
    private TransactionService transactionService;
    @Autowired
    private UserCardService userCardService;
    @Autowired
    private RedisComponent redisComponent;

    /**
     * 每天凌晨1点指定
     */
//    @Scheduled(cron = "0 0 10 * * ?")
//    public void task() {
//        logger.info("每日跑批开始");
//        try {
//            Calendar calendar = Calendar.getInstance();
//            calendar.add(Calendar.DAY_OF_MONTH, -1);
//            Date startDate = DateUtil.getDayBeginDate(calendar.getTime());
//            Date endDate = DateUtil.getDayEndDate(calendar.getTime());
//            int page = 1;
//            int size = 100;
//            PageDataOfClear clearData;
//            do {
//                clearData = pingPongComponent.queryClearData(
//                        DateUtil.format("yyyy-MM-dd", startDate),
//                        DateUtil.format("yyyy-MM-dd", endDate),
//                        page++,
//                        size
//                );
//                ArrayList<ClearTran> list = new ArrayList<>();
//                for (Clear clear : clearData.getList()) {
//                    if (!clearTranService.existsByClearTransactionId(clear.getTransactionId())) {
//                        UserCard userCard = userCardService.getByChannelCrdIdOrNullAndEmpty(clear.getPpCardId());
//                        if (userCard != null) {
//                            ClearTran clearTran = new ClearTran();
//                            clearTran.setTransactionId(clear.getTransactionId());
//                            clearTran.setCardId(userCard.getCardId());
//                            clearTran.setUserId(userCard.getUserId());
//                            clearTran.setCardNumber(userCard.getCardNumber());
//                            clearTran.setMerchantName(clear.getMerchantName());
//                            clearTran.setTranDate(DateUtil.parse(clear.getTransactionDate(), "yyyy-MM-dd"));
//                            clearTran.setPostingDate(DateUtil.parse(clear.getPostingDate(), "yyyy-MM-dd"));
//                            clearTran.setBillingAmount(new BigDecimal(clear.getBillingAmount()));
//                            clearTran.setBillingCurrency(clear.getBillingCurrency());
//                            clearTran.setType(clear.getType());
//                            clearTran.setRemark("");
//                            list.add(clearTran);
//                        }
//                    }
//                }
//                clearTranService.saveBatch(list);
//            } while (clearData.getList().size() == size);
//            authTask(startDate, endDate);
//            logger.info("每日跑批结束");
//        } catch (Exception e) {
//            logger.error("跑批任务异常", e);
//        }
//    }
//
//
//    public void authTask(Date startDate, Date endDate) {
//        try {
//            int page = 1;
//            int size = 100;
//            PageDataOfAuth authData;
//            do {
//                authData = pingPongComponent.queryAuthData(
//                        DateUtil.format("yyyy-MM-dd HH:mm:ss", startDate),
//                        DateUtil.format("yyyy-MM-dd HH:mm:ss", endDate),
//                        page++,
//                        size
//                );
//                ArrayList<AuthTran> list = new ArrayList<>();
//                for (Auth auth : authData.getList()) {
//                    if (!authTranService.existsByTranId(auth.getAuthorizationId())) {
//                        UserCard userCard = userCardService.getByChannelCrdIdOrNullAndEmpty(auth.getPpCardId());
//                        if (userCard != null) {
//                            AuthTran authTran = new AuthTran();
//                            authTran.setTranId(auth.getAuthorizationId());
//                            authTran.setCardId(userCard.getCardId());
//                            authTran.setCardNumber(userCard.getCardNumber());
//                            authTran.setUserId(userCard.getUserId());
//                            authTran.setMerchantName(auth.getMerchantName());
//                            authTran.setTranDate(DateUtil.parse(auth.getAuthorizationDate()));
//                            authTran.setBillingAmount(new BigDecimal(auth.getBillingAmount()));
//                            authTran.setBillingCurrency(auth.getBillingCurrency());
//                            authTran.setMerchantAmount(new BigDecimal(auth.getMerchantAmount()));
//                            authTran.setMerchantCurrency(auth.getMerchantCurrency());
//                            authTran.setAuthType(auth.getAuthorizationType());
//                            authTran.setRemark(auth.getRemark());
//                            authTran.setStatus(auth.getAuthorizationStatus());
//                            authTran.setMcc(auth.getMcc());
//                            list.add(authTran);
//                        }
//                    }
//                }
//                authTranService.saveBatch(list);
//            } while (authData.getList().size() == size);
//        } catch (Exception e) {
//            logger.error("跑批任务异常", e);
//        }
//    }
//

}
